In [1]:
from __future__ import print_function, division

In [2]:
# This changes the current directory to the base saga directory - make sure to run this first!
# This is necessary to be able to import the py files and use the right directories,
# while keeping all the notebooks in their own directory.
import os
import sys
from time import time

if 'saga_base_dir' not in locals():
    saga_base_dir = os.path.abspath('..')
if saga_base_dir not in sys.path:
    os.chdir(saga_base_dir)

In [3]:
import hosts
import targeting

import numpy as np

from scipy import interpolate

from astropy import units as u
from astropy.coordinates import SkyCoord
from astropy import table
from astropy.table import Table
from astropy.io import fits

from astropy.utils.console import ProgressBar

from collections import Counter

In [4]:
%matplotlib inline
from matplotlib import style, pyplot as plt

plt.style.use('seaborn-deep')
plt.rcParams['image.cmap'] = 'viridis'
plt.rcParams['image.origin'] = 'lower'
plt.rcParams['figure.figsize'] = (14, 8)
plt.rcParams['axes.titlesize'] =  plt.rcParams['axes.labelsize'] = 16
plt.rcParams['xtick.labelsize'] =  plt.rcParams['ytick.labelsize'] = 14

In [5]:
from IPython import display
from decals import make_cutout_comparison_table, fluxivar_to_mag_magerr, compute_sb, DECALS_AP_SIZES, band_to_idx, subselect_aperture

Parts adapted from DECALS low-SB_completeness AnaK overlap.ipynb

Get AnaK Info and download


In [6]:
hsts = hosts.get_saga_hosts_from_google(clientsecretjsonorfn='client_secrets.json', useobservingsummary=False)
anak  = [h for h in hsts if h.name=='AnaK']
assert len(anak)==1
anak = anak[0]


Using cached version of google hosts list from file "hosts_dl.pkl2"

In [7]:
bricknames = []
with open('decals_dr3/anakbricks') as f:
    for l in f:
        l = l.strip()
        if l != '':
            bricknames.append(l)
print(bricknames)


['3538m007', '3541m007', '3543m007', '3546m007', '3533m005', '3536m005', '3538m005', '3541m005', '3543m005', '3546m005', '3548m005', '3531m002', '3533m002', '3536m002', '3538m002', '3541m002', '3543m002', '3546m002', '3548m002', '3551m002', '3531p000', '3533p000', '3536p000', '3538p000', '3541p000', '3543p000', '3546p000', '3548p000', '3551p000', '3531p002', '3533p002', '3536p002', '3538p002', '3541p002', '3543p002', '3546p002', '3548p002', '3551p002', '3531p005', '3533p005', '3536p005', '3538p005', '3541p005', '3543p005', '3546p005', '3548p005', '3551p005', '3531p007', '3533p007', '3536p007', '3538p007', '3541p007', '3543p007', '3546p007', '3548p007', '3551p007', '3533p010', '3536p010', '3538p010', '3541p010', '3543p010', '3546p010', '3548p010', '3536p012', '3538p012', '3541p012', '3543p012', '3546p012']

In [8]:
base_url = 'http://portal.nersc.gov/project/cosmo/data/legacysurvey/dr3/tractor/{first3}/tractor-{brickname}.fits'

for brickname in ProgressBar(bricknames, ipython_widget=True):
    url = base_url.format(brickname=brickname, first3=brickname[:3])
    target = os.path.join('decals_dr3/catalogs/', url.split('/')[-1])
    if not os.path.isfile(target):
        !wget $url -O $target
    else:
        print(target, 'already exists, not downloading')


decals_dr3/catalogs/tractor-3538m007.fits already exists, not downloading
decals_dr3/catalogs/tractor-3541m007.fits already exists, not downloading
decals_dr3/catalogs/tractor-3543m007.fits already exists, not downloading
decals_dr3/catalogs/tractor-3546m007.fits already exists, not downloading
decals_dr3/catalogs/tractor-3533m005.fits already exists, not downloading
decals_dr3/catalogs/tractor-3536m005.fits already exists, not downloading
decals_dr3/catalogs/tractor-3538m005.fits already exists, not downloading
decals_dr3/catalogs/tractor-3541m005.fits already exists, not downloading
decals_dr3/catalogs/tractor-3543m005.fits already exists, not downloading
decals_dr3/catalogs/tractor-3546m005.fits already exists, not downloading
decals_dr3/catalogs/tractor-3548m005.fits already exists, not downloading
decals_dr3/catalogs/tractor-3531m002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3533m002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3536m002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3538m002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3541m002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3543m002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3546m002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3548m002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3551m002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3531p000.fits already exists, not downloading
decals_dr3/catalogs/tractor-3533p000.fits already exists, not downloading
decals_dr3/catalogs/tractor-3536p000.fits already exists, not downloading
decals_dr3/catalogs/tractor-3538p000.fits already exists, not downloading
decals_dr3/catalogs/tractor-3541p000.fits already exists, not downloading
decals_dr3/catalogs/tractor-3543p000.fits already exists, not downloading
decals_dr3/catalogs/tractor-3546p000.fits already exists, not downloading
decals_dr3/catalogs/tractor-3548p000.fits already exists, not downloading
decals_dr3/catalogs/tractor-3551p000.fits already exists, not downloading
decals_dr3/catalogs/tractor-3531p002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3533p002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3536p002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3538p002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3541p002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3543p002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3546p002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3548p002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3551p002.fits already exists, not downloading
decals_dr3/catalogs/tractor-3531p005.fits already exists, not downloading
decals_dr3/catalogs/tractor-3533p005.fits already exists, not downloading
decals_dr3/catalogs/tractor-3536p005.fits already exists, not downloading
decals_dr3/catalogs/tractor-3538p005.fits already exists, not downloading
decals_dr3/catalogs/tractor-3541p005.fits already exists, not downloading
decals_dr3/catalogs/tractor-3543p005.fits already exists, not downloading
decals_dr3/catalogs/tractor-3546p005.fits already exists, not downloading
decals_dr3/catalogs/tractor-3548p005.fits already exists, not downloading
decals_dr3/catalogs/tractor-3551p005.fits already exists, not downloading
decals_dr3/catalogs/tractor-3531p007.fits already exists, not downloading
decals_dr3/catalogs/tractor-3533p007.fits already exists, not downloading
decals_dr3/catalogs/tractor-3536p007.fits already exists, not downloading
decals_dr3/catalogs/tractor-3538p007.fits already exists, not downloading
decals_dr3/catalogs/tractor-3541p007.fits already exists, not downloading
decals_dr3/catalogs/tractor-3543p007.fits already exists, not downloading
decals_dr3/catalogs/tractor-3546p007.fits already exists, not downloading
decals_dr3/catalogs/tractor-3548p007.fits already exists, not downloading
decals_dr3/catalogs/tractor-3551p007.fits already exists, not downloading
decals_dr3/catalogs/tractor-3533p010.fits already exists, not downloading
decals_dr3/catalogs/tractor-3536p010.fits already exists, not downloading
decals_dr3/catalogs/tractor-3538p010.fits already exists, not downloading
decals_dr3/catalogs/tractor-3541p010.fits already exists, not downloading
decals_dr3/catalogs/tractor-3543p010.fits already exists, not downloading
decals_dr3/catalogs/tractor-3546p010.fits already exists, not downloading
decals_dr3/catalogs/tractor-3548p010.fits already exists, not downloading
decals_dr3/catalogs/tractor-3536p012.fits already exists, not downloading
decals_dr3/catalogs/tractor-3538p012.fits already exists, not downloading
decals_dr3/catalogs/tractor-3541p012.fits already exists, not downloading
decals_dr3/catalogs/tractor-3543p012.fits already exists, not downloading
decals_dr3/catalogs/tractor-3546p012.fits already exists, not downloading


In [9]:
bricks = Table.read('decals_dr3/survey-bricks.fits.gz')
bricksdr3 = Table.read('decals_dr3/survey-bricks-dr3.fits.gz')

In [10]:
catalog_fns = ['decals_dr3/catalogs/tractor-{}.fits'.format(bnm) for bnm in bricknames]
decals_catalogs = [Table.read(fn) for fn in catalog_fns]
dcatall = table.vstack(decals_catalogs, metadata_conflicts='silent')


WARNING: UnitsWarning: '1/deg^2' did not parse as fits unit: Numeric factor not supported by FITS [astropy.units.core]
WARNING:astropy:UnitsWarning: '1/deg^2' did not parse as fits unit: Numeric factor not supported by FITS
WARNING: UnitsWarning: 'nanomaggy' did not parse as fits unit: At col 0, Unit 'nanomaggy' not supported by the FITS standard.  [astropy.units.core]
WARNING:astropy:UnitsWarning: 'nanomaggy' did not parse as fits unit: At col 0, Unit 'nanomaggy' not supported by the FITS standard. 
WARNING: UnitsWarning: '1/nanomaggy^2' did not parse as fits unit: Numeric factor not supported by FITS [astropy.units.core]
WARNING:astropy:UnitsWarning: '1/nanomaggy^2' did not parse as fits unit: Numeric factor not supported by FITS
WARNING: UnitsWarning: '1/arcsec^2' did not parse as fits unit: Numeric factor not supported by FITS [astropy.units.core]
WARNING:astropy:UnitsWarning: '1/arcsec^2' did not parse as fits unit: Numeric factor not supported by FITS

In [11]:
sdss_catalog = Table.read('catalogs/base_sql_nsa{}.fits.gz'.format(anak.nsaid))

basic photometric addtions to the catalogs


In [176]:
for dcat in [dcatall]:
    for magnm, idx in zip('grz', [1, 2, 4]):
        mag, mag_err = fluxivar_to_mag_magerr(dcat['decam_flux'][:, idx], dcat['decam_flux_ivar'][:, idx])
        dcat[magnm] = mag
        dcat[magnm + '_err'] = mag_err
    
    dcat['sb_r_0.5'] = compute_sb(0.5*u.arcsec, dcat['decam_apflux'][:, 2, :])
    dcat['sb_r_0.75'] = compute_sb(0.75*u.arcsec, dcat['decam_apflux'][:, 2, :])
    dcat['sb_r_1'] = compute_sb(1.0*u.arcsec, dcat['decam_apflux'][:, 2, :])
    dcat['sb_r_2'] = compute_sb(2.0*u.arcsec, dcat['decam_apflux'][:, 2, :])

Basic residual comparisons


In [12]:
DECALS_AP_SIZES


Out[12]:
$[0.5,~0.75,~1,~1.5,~2,~3.5,~5,~7] \; \mathrm{{}^{\prime\prime}}$

In [287]:
apmag, apmagerr = fluxivar_to_mag_magerr(dcatall['decam_apflux'], dcatall['decam_apflux_ivar'])
apmagres, _ = fluxivar_to_mag_magerr(dcatall['decam_apflux_resid'], dcatall['decam_apflux_ivar'])

In [289]:
apdiff = subselect_aperture(apmagres - apmag, 'r')
apcolor = subselect_aperture(apmag, 'g') - subselect(apmag, 'r')
apmagx = subselect_aperture(apmag, 'r')

good = ~np.isnan(apdiff)&~np.isnan(apcolor)&~np.isnan(apmagx)

plt.scatter(apcolor[good], apmagx[good], c=apdiff[good], cmap='viridis', alpha=.1, lw=0, s=1)
plt.colorbar()
plt.xlim(-2,5)
plt.ylim(26,15)


/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:1: RuntimeWarning: invalid value encountered in subtract
  if __name__ == '__main__':
/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:2: RuntimeWarning: invalid value encountered in subtract
  from ipykernel import kernelapp as app
Out[289]:
(26, 15)

Inspect objects with failed residuals


In [290]:
for band in 'ugrizy':
    reses = subselect_aperture(apmagres, band, None)
    print('Band', band)
    for ap, res in zip(DECALS_AP_SIZES, reses.T):
        print('Aperture', ap,'has', 100*np.sum(np.isfinite(res))/len(res),'% good')


Band u
Aperture 0.5 arcsec has 0.0 % good
Aperture 0.75 arcsec has 0.0 % good
Aperture 1.0 arcsec has 0.0 % good
Aperture 1.5 arcsec has 0.0 % good
Aperture 2.0 arcsec has 0.0 % good
Aperture 3.5 arcsec has 0.0 % good
Aperture 5.0 arcsec has 0.0 % good
Aperture 7.0 arcsec has 0.0 % good
Band g
Aperture 0.5 arcsec has 69.4069194652 % good
Aperture 0.75 arcsec has 78.1477336963 % good
Aperture 1.0 arcsec has 80.8846025172 % good
Aperture 1.5 arcsec has 62.2562670881 % good
Aperture 2.0 arcsec has 39.6218404993 % good
Aperture 3.5 arcsec has 13.3274113725 % good
Aperture 5.0 arcsec has 6.7775688428 % good
Aperture 7.0 arcsec has 4.14844894616 % good
Band r
Aperture 0.5 arcsec has 53.488919396 % good
Aperture 0.75 arcsec has 63.3932835735 % good
Aperture 1.0 arcsec has 63.5275659587 % good
Aperture 1.5 arcsec has 50.9597037481 % good
Aperture 2.0 arcsec has 38.2667881822 % good
Aperture 3.5 arcsec has 17.9269291557 % good
Aperture 5.0 arcsec has 10.3159789117 % good
Aperture 7.0 arcsec has 6.40148587382 % good
Band i
Aperture 0.5 arcsec has 0.0 % good
Aperture 0.75 arcsec has 0.0 % good
Aperture 1.0 arcsec has 0.0 % good
Aperture 1.5 arcsec has 0.0 % good
Aperture 2.0 arcsec has 0.0 % good
Aperture 3.5 arcsec has 0.0 % good
Aperture 5.0 arcsec has 0.0 % good
Aperture 7.0 arcsec has 0.0 % good
Band z
Aperture 0.5 arcsec has 52.2090836727 % good
Aperture 0.75 arcsec has 60.242492761 % good
Aperture 1.0 arcsec has 58.6744805787 % good
Aperture 1.5 arcsec has 48.5366219443 % good
Aperture 2.0 arcsec has 39.4995558529 % good
Aperture 3.5 arcsec has 24.0720787236 % good
Aperture 5.0 arcsec has 17.1657649135 % good
Aperture 7.0 arcsec has 12.8175074697 % good
Band y
Aperture 0.5 arcsec has 0.0 % good
Aperture 0.75 arcsec has 0.0 % good
Aperture 1.0 arcsec has 0.0 % good
Aperture 1.5 arcsec has 0.0 % good
Aperture 2.0 arcsec has 0.0 % good
Aperture 3.5 arcsec has 0.0 % good
Aperture 5.0 arcsec has 0.0 % good
Aperture 7.0 arcsec has 0.0 % good

???? Why are so many of the residuals NaN/infs ???


In [291]:
rs = subselect_aperture(apmagres, 'r')
catnotfin = dcatall[~np.isfinite(rs)]
catnotfin['apmagres_allaps'] = subselect_aperture(apmagres, 'r', None)[~np.isfinite(rs)]

make_cutout_comparison_table(catnotfin[np.random.permutation(len(catnotfin))[:10]], 
                             inclres=True, inclmod=True, inclsdss=False, doprint=False,
                             add_annotation=['apmagres_allaps'])


Out[291]:
objDECALSDECALS modelsDECALS residuals
331785_2836
ra=354.296579462
dec=-0.00381013739397
r=21.2191448212
sb_r_0.5=23.0795593262
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
apmagres_allaps=[ nan nan nan nan 25.31560326 24.42445564 23.92601585 25.14506912]
338983_5072
ra=353.865196795
dec=1.3658715141
r=23.7452030182
sb_r_0.5=24.1735706329
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
apmagres_allaps=[ 28.18408966 nan nan nan nan 24.37808228 25.29845047 24.57925034]
328902_3494
ra=353.640930955
dec=-0.491863289749
r=20.8895130157
sb_r_0.5=22.7217140198
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
apmagres_allaps=[ 28.34125519 nan nan nan 24.69011497 23.78873444 25.51941872 nan]
333225_6559
ra=354.360712397
dec=0.362609039521
r=24.2036151886
sb_r_0.5=24.7513847351
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
apmagres_allaps=[ 27.30080605 nan nan nan nan nan nan nan]
328907_3409
ra=354.827657889
dec=-0.4740923194
r=17.1656970978
sb_r_0.5=17.8682518005
decam_anymask=[0 0 0 0 1 0]
decam_allmask=[0 0 0 0 0 0]
apmagres_allaps=[ nan nan nan nan nan nan nan nan]
331785_777
ra=354.39330361
dec=-0.0945746315033
r=23.2419872284
sb_r_0.5=24.3415966034
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
apmagres_allaps=[ nan nan nan nan nan nan nan nan]
328904_2565
ra=354.250565081
dec=-0.537351472796
r=24.4224777222
sb_r_0.5=25.2684898376
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
apmagres_allaps=[ 28.93747139 nan nan nan 28.57262611 nan nan nan]
334666_4700
ra=354.646148315
dec=0.549476008802
r=25.3721466064
sb_r_0.5=26.1215991974
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
apmagres_allaps=[ 28.88192749 nan nan 26.19467163 nan nan nan nan]
330341_4000
ra=353.261257901
dec=-0.231385111146
r=23.4945716858
sb_r_0.5=24.3669052124
decam_anymask=[0 0 1 0 0 0]
decam_allmask=[0 0 0 0 0 0]
apmagres_allaps=[ 27.42296982 26.75622559 nan nan nan nan nan nan]
333222_5507
ra=353.755771795
dec=0.347957586529
r=21.6146183014
sb_r_0.5=22.3003253937
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
apmagres_allaps=[ nan nan nan 24.39198685 23.50357246 23.60165787 23.39720726 23.29241562]

Inspect objects with high residuals vs. flux

Note that this includes only those with r<22 to ensure there's not a flux effect


In [292]:
dmag_of_ap_distr = {}

for ap in DECALS_AP_SIZES:
    rs = subselect_aperture(apmag, 'r', ap)
    rres = subselect_aperture(apmagres, 'r', ap)

    dmag_of_ap_distr[ap] = dmag = rs - rres
    plt.hist(dmag[np.isfinite(dmag)&(rs<22*u.mag)], bins=100, histtype='step', label=str(ap), normed=True)
    
plt.legend(loc=0)
plt.xlabel('r_flux - r_resid')


/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:7: RuntimeWarning: invalid value encountered in subtract
/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:8: RuntimeWarning: invalid value encountered in less
Out[292]:
<matplotlib.text.Text at 0x1b838f350>

In [267]:
ap = 1.0*u.arcsec

rs = subselect_aperture(apmag, 'r', ap)
rres = subselect_aperture(apmagres, 'r', ap)
dmag = rs - rres

perc = 95
p = np.percentile(dmag[np.isfinite(dmag)&(rs<22*u.mag)], perc)
print('nobjs in', perc,'percentile:', np.sum(dmag.value>p), 'cutoff is', p)

msk = np.isfinite(dmag)&(dmag.value>p)&(rs<22*u.mag)
dcatbadres = dcatall[msk]
dcatbadres['dmag'] = dmag[msk]
dcatbadres['r'] = rs[msk]

make_cutout_comparison_table(dcatbadres[:10], 
                             inclres=True, inclmod=True, inclsdss=False, doprint=False,
                             add_annotation=['dmag', 'r'])


nobjs in 95 percentile: 171762 cutoff is -3.6490696907
/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:5: RuntimeWarning: invalid value encountered in subtract
/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:8: RuntimeWarning: invalid value encountered in less
/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:9: RuntimeWarning: invalid value encountered in greater
/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:11: RuntimeWarning: invalid value encountered in greater
/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:11: RuntimeWarning: invalid value encountered in less
Out[267]:
objDECALSDECALS modelsDECALS residuals
327463_333
ra=353.806181204
dec=-0.867842838291
r=21.0201034546
sb_r_0.5=21.9509525299
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-2.8453578949
r=21.0201034546
327463_691
ra=353.838570951
dec=-0.854908081239
r=21.2911548615
sb_r_0.5=21.8991966248
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-3.33714675903
r=21.2911548615
327463_946
ra=353.970447627
dec=-0.848001103365
r=21.9249153137
sb_r_0.5=22.5107021332
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-3.3512840271
r=21.9249153137
327463_1318
ra=353.934400217
dec=-0.835109864606
r=21.29845047
sb_r_0.5=21.8545284271
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-3.13621902466
r=21.29845047
327463_2165
ra=353.984296108
dec=-0.799618561569
r=19.8145370483
sb_r_0.5=20.8664073944
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-2.5799369812
r=19.8145370483
327463_2191
ra=353.919553199
dec=-0.801457587582
r=21.5625934601
sb_r_0.5=22.1220340729
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-3.57859992981
r=21.5625934601
327463_2779
ra=353.889962208
dec=-0.77453736284
r=20.9005184174
sb_r_0.5=21.9076519012
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-2.96533966064
r=20.9005184174
327463_2908
ra=353.779929784
dec=-0.769737173087
r=16.4941921234
sb_r_0.5=17.2371196747
decam_anymask=[0 0 3 0 2 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-1.66430854797
r=16.4941921234
327463_3207
ra=353.761256263
dec=-0.761058869207
r=20.6356163025
sb_r_0.5=21.6629867554
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-1.62988090515
r=20.6356163025
327463_3666
ra=353.884375584
dec=-0.740239136879
r=21.62383461
sb_r_0.5=22.2448120117
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-2.8863697052
r=21.62383461

X-matching to SDSS


In [268]:
#cut out the non-overlap region
dsc = SkyCoord(dcatall['ra'], dcatall['dec'], unit=u.deg)
dcutall = dcatall[dsc.separation(anak.coords) < 1*u.deg]

In [269]:
dsc = SkyCoord(dcutall['ra'], dcutall['dec'], unit=u.deg)
ssc = SkyCoord(sdss_catalog['ra'], sdss_catalog['dec'], unit=u.deg)
threshold = 1*u.arcsec

In [270]:
idx, d2d, _ = ssc.match_to_catalog_sky(dsc)
plt.hist(d2d.arcsec, bins=100, range=(0, 3),histtype='step', log=True)
plt.axvline(threshold.to(u.arcsec).value, c='k')
None



In [271]:
dmatchmsk = idx[d2d<threshold]
dmatch = dcutall[dmatchmsk]

smatch = sdss_catalog[d2d<threshold]

In [272]:
idx, d2d, _ = dsc.match_to_catalog_sky(ssc)
dnomatchmsk = d2d>threshold
dnomatch = dcutall[dnomatchmsk]

In [273]:
plt.figure(figsize=(12, 10))

xnm = 'r'
ynm = 'sb_r_0.5'

ap = 1*u.arcsec

apmag, apmagerr = fluxivar_to_mag_magerr(dnomatch['decam_apflux'], dnomatch['decam_apflux_ivar'])
apmagres, _ = fluxivar_to_mag_magerr(dnomatch['decam_apflux_resid'], dnomatch['decam_apflux_ivar'])
rs = subselect_aperture(apmag, xnm, ap)
rres = subselect_aperture(apmagres, xnm, ap)
dmag = rs - rres




dnstar = dnomatch['type']=='PSF '
dnoext = -2.5*np.log10(dnomatch['decam_mw_transmission'][:, 2])
r0 = (dnomatch[xnm] - dnoext)
sb = dnomatch[ynm] - dnoext
plt.scatter(r0[~dnstar], sb[~dnstar], 
            c=dmag[~dnstar], lw=0, alpha=1, s=3, label='Glx in DECALS, not in SDSS', vmax=0, vmin=-5,
            cmap='viridis_r')
plt.colorbar().set_label('r_ap - r_res [{}]'.format(ap))

plt.axvline(20.75, color='k', ls=':')

plt.xlim(17, 23)
plt.ylim(18, 28)

plt.xlabel(r'$r_{0, {\rm DECaLS}}$', fontsize=28)
plt.ylabel(r'$SB_{0.5^{\prime \prime}, {\rm DECaLS}}$', fontsize=28)
plt.xticks(fontsize=24)
plt.yticks(fontsize=24)

plt.legend(loc='lower right', fontsize=20)


/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:12: RuntimeWarning: invalid value encountered in subtract
Out[273]:
<matplotlib.legend.Legend at 0x195c3dc90>

now inspect those that are in the upper-left of that plot


In [274]:
msk = (r0[~dnstar]<20.75)&(sb[~dnstar]>24)
cat = dnomatch[~dnstar][msk]
cat['dmag'] = dmag[~dnstar][msk]


/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:1: RuntimeWarning: invalid value encountered in less
  if __name__ == '__main__':
/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:1: RuntimeWarning: invalid value encountered in greater
  if __name__ == '__main__':

In [275]:
p = np.percentile(cat['dmag'][np.isfinite(cat['dmag'])], 10)

catlower = cat[cat['dmag']<p]
print(len(catlower))
make_cutout_comparison_table(catlower[np.random.permutation(len(catupper))[:10]], 
                             inclres=True, inclmod=True, inclsdss=False, doprint=False,
                             add_annotation=['dmag', 'r'])


23
/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:3: RuntimeWarning: invalid value encountered in less
  app.launch_new_instance()
Out[275]:
objDECALSDECALS modelsDECALS residuals
334666_3661
ra=354.639361466
dec=0.510723073664
r=20.0610847473
sb_r_0.5=24.0979118347
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-3.16948699951
r=20.0610847473
330344_2707
ra=354.234954635
dec=-0.279673254343
r=20.2862873077
sb_r_0.5=24.0953636169
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-3.08874320984
r=20.2862873077
337544_4913
ra=353.994135512
dec=1.0573178057
r=20.37225914
sb_r_0.5=24.4389324188
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-3.36192321777
r=20.37225914
331783_5641
ra=353.789095491
dec=0.0960012819639
r=20.7215423584
sb_r_0.5=24.2212142944
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-3.78756713867
r=20.7215423584
331787_3512
ra=354.986221604
dec=0.0227201786246
r=20.6646556854
sb_r_0.5=24.579832077
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-5.21674156189
r=20.6646556854
331784_4245
ra=354.214001677
dec=0.0384587839212
r=19.7916584015
sb_r_0.5=26.1460857391
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-3.361120224
r=19.7916584015
336107_3602
ra=354.96017355
dec=0.749478844416
r=20.331993103
sb_r_0.5=26.4045829773
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-3.14507675171
r=20.331993103
337543_1011
ra=353.853768127
dec=0.908521771402
r=20.0452613831
sb_r_0.5=24.3184623718
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-6.39757156372
r=20.0452613831
336105_819
ra=354.425934842
dec=0.656971971086
r=20.1120910645
sb_r_0.5=26.125082016
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-3.09093666077
r=20.1120910645
331784_3784
ra=354.048195606
dec=0.0181465340088
r=20.3882141113
sb_r_0.5=25.1399726868
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-4.59214019775
r=20.3882141113

In [276]:
p = np.percentile(cat['dmag'][np.isfinite(cat['dmag'])], 90)

catupper = cat[cat['dmag']>p]
print(len(catupper))
make_cutout_comparison_table(catupper[np.random.permutation(len(catupper))[:10]], 
                             inclres=True, inclmod=True, inclsdss=False, doprint=False,
                             add_annotation=['dmag', 'r'])


22
/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:3: RuntimeWarning: invalid value encountered in greater
  app.launch_new_instance()
Out[276]:
objDECALSDECALS modelsDECALS residuals
333225_3358
ra=354.248466103
dec=0.247182021251
r=19.6161441803
sb_r_0.5=25.2402858734
decam_anymask=[0 1 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=0.458927154541
r=19.6161441803
338984_2407
ra=354.240040817
dec=1.22365483566
r=20.1240921021
sb_r_0.5=24.9921379089
decam_anymask=[0 0 1 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-0.124256134033
r=20.1240921021
331780_6320
ra=353.256240386
dec=0.128289642121
r=17.1680393219
sb_r_0.5=inf
decam_anymask=[ 0 1 66 0 2 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-0.15439414978
r=17.1680393219
337542_10
ra=353.660214336
dec=0.86883192993
r=20.3064670563
sb_r_0.5=inf
decam_anymask=[0 1 0 0 1 0]
decam_allmask=[0 0 0 0 0 0]
dmag=0.0297222137451
r=20.3064670563
333223_5169
ra=353.962108239
dec=0.333925799191
r=20.7443904877
sb_r_0.5=24.1393260956
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-0.0622119903564
r=20.7443904877
333222_1657
ra=353.634532164
dec=0.191952261972
r=20.8096351624
sb_r_0.5=25.4466533661
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-0.193748474121
r=20.8096351624
334663_2808
ra=353.882764988
dec=0.483849258436
r=19.9570236206
sb_r_0.5=25.9705181122
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-0.119953155518
r=19.9570236206
333224_141
ra=353.994248716
dec=0.125333757659
r=20.3014984131
sb_r_0.5=25.6945781708
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-0.180147171021
r=20.3014984131
330344_27
ra=354.115974678
dec=-0.377204211692
r=20.8271369934
sb_r_0.5=26.8624172211
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-0.182638168335
r=20.8271369934
331782_664
ra=353.494063228
dec=-0.102765028355
r=19.7340869904
sb_r_0.5=24.3124847412
decam_anymask=[0 0 0 0 1 0]
decam_allmask=[0 0 0 0 0 0]
dmag=-0.187227249146
r=19.7340869904

In [277]:
# things we want to identify automatically
disky_things_from_marla = """
mag ra dec unk
19.4785    354.157853072    0.102747198705    false
19.3311    354.255069696    0.619242808225    false
19.1127    354.284237813    0.160859730123    false
18.6914    354.069400831    -0.115904590235    false
19.3392    354.415038652    -0.0645766794736    false
19.4624    354.114525096    0.00532483801292    false
19.1087    354.534841322    0.436958919955    false
19.0242    354.447705125    0.266811924681    false
19.0354    354.136706143    0.691858529943    false
19.0534    354.53888635    0.236989192453    false
19.2452    354.568916976    0.837946572935    false
19.3481    353.473924073    -0.0912764847886    false
19.268    354.011615043    -0.445983276629    false
19.3429    354.408722681    0.904017267882    true
19.1914    354.851596507    0.401264434888    true
19.2529    353.412613626    0.640755638979    false
19.3848    354.878706758    0.364835196656    false
"""
disky_things_from_marla = Table.read([disky_things_from_marla], format='ascii')

In [254]:
sc_marla = SkyCoord(disky_things_from_marla['ra'], disky_things_from_marla['dec'], unit=u.deg)
idx, d2d, _ = sc_marla.match_to_catalog_sky(SkyCoord(dcatall['ra'], dcatall['dec'], unit=u.deg))
np.sum(d2d < 1*u.arcsec)/len(d2d)


Out[254]:
1.0

In [314]:
matchcat = dcatall[idx]

apmag, apmagerr = fluxivar_to_mag_magerr(matchcat['decam_apflux'], matchcat['decam_apflux_ivar'])
apmagres, _ = fluxivar_to_mag_magerr(matchcat['decam_apflux_resid'], matchcat['decam_apflux_ivar'])
rs = subselect_aperture(apmag, xnm, None)
rres = subselect_aperture(apmagres, xnm, None)
matchcat['dmag'] = rs - rres

dmagsigs = []
for dmag, dmagdistr in zip(matchcat['dmag'].T, dmag_of_ap_distr.values()):
    msk = np.isfinite(dmagdistr)
    dmagsigs.append(np.mean(dmagdistr[msk].value)-dmag/np.std(dmagdistr[msk].value))
    print(np.mean(dmagdistr[msk].value).shape, dmag.shape, np.std(dmagdistr[msk].value).shape, dmagsigs[-1].shape)
matchcat['dmag_sig'] = np.array(dmagsigs).T


make_cutout_comparison_table(matchcat[np.random.permutation(len(matchcat))[:10]], 
                             inclres=True, inclmod=True, inclsdss=False, doprint=False,
                             add_annotation=['dmag', 'r', 'dmag_sig'])


() (323472,) () (323472,)
() (323472,) () (323472,)
() (323472,) () (323472,)
() (323472,) () (323472,)
() (323472,) () (323472,)
() (323472,) () (323472,)
() (323472,) () (323472,)
() (323472,) () (323472,)
/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:7: RuntimeWarning: invalid value encountered in subtract
Out[314]:
objDECALSDECALS modelsDECALS residuals
327464_5590
ra=354.099630767
dec=-0.66554203829
r=25.0883693695
sb_r_0.5=25.6132011414
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=[-1.88580322 nan nan nan nan nan nan nan]
r=25.0883693695
dmag_sig=[-2.25059295 nan nan nan nan nan nan nan]
328906_4412
ra=354.560906857
dec=-0.454901915337
r=24.6024990082
sb_r_0.5=25.5351066589
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=[ nan -2.05608559 -1.60516357 nan nan nan nan nan]
r=24.6024990082
dmag_sig=[ nan -2.01026964 -2.19438505 nan nan nan nan nan]
328906_3373
ra=354.498101341
dec=-0.496813363141
r=24.2625370026
sb_r_0.5=25.1857299805
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=[-3.87623405 -3.06590843 -3.89391708 nan nan nan nan nan]
r=24.2625370026
dmag_sig=[-1.15172553 -1.41551518 -0.68962598 nan nan nan nan nan]
328905_491
ra=354.303625984
dec=-0.610651825151
r=24.8817100525
sb_r_0.5=25.3493938446
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=[-2.32224083 nan nan nan -2.34275246 nan nan nan]
r=24.8817100525
dmag_sig=[-2.00964665 nan nan nan -1.75352502 nan nan nan]
328901_6283
ra=353.354975901
dec=-0.374638095606
r=16.5132331848
sb_r_0.5=17.39220047
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=[ nan nan -6.90778732 -6.09369659 -5.89782333 -5.79778481 -5.87242889 -5.70718575]
r=16.5132331848
dmag_sig=[ nan nan 1.29186678 0.63409257 0.60842991 0.37828755 0.35445309 0.43777514]
328903_2470
ra=353.931930098
dec=-0.524503756306
r=23.5829296112
sb_r_0.5=24.4537811279
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=[-2.52700424 -2.96908569 -3.29784012 nan nan nan nan nan]
r=23.5829296112
dmag_sig=[-1.8966018 -1.47254074 -1.08152151 nan nan nan nan nan]
330340_4962
ra=353.152727986
dec=-0.187472812585
r=21.9512863159
sb_r_0.5=23.2379131317
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=[-4.81995201 -7.17699623 -5.9567318 nan nan nan nan nan]
r=21.9512863159
dmag_sig=[-0.63072252 1.00578833 0.66658807 nan nan nan nan nan]
330340_5332
ra=353.067656491
dec=-0.17299303237
r=28.6773090363
sb_r_0.5=26.6103534698
decam_anymask=[0 0 1 0 1 0]
decam_allmask=[0 0 0 0 0 0]
dmag=[-0.14296341 -0.2022934 nan nan nan nan nan nan]
r=28.6773090363
dmag_sig=[-3.21277142 -3.10209608 nan nan nan nan nan nan]
328901_313
ra=353.48071893
dec=-0.616824108196
r=24.7708816528
sb_r_0.5=25.0010166168
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=[-3.0931263 -3.32744789 -4.02608681 -4.17303467 nan nan nan nan]
r=24.7708816528
dmag_sig=[-1.58405995 -1.26147652 -0.6027298 -0.56338096 nan nan nan nan]
327466_1461
ra=354.640470946
dec=-0.816300578754
r=24.7094020844
sb_r_0.5=25.4035987854
decam_anymask=[0 0 0 0 0 0]
decam_allmask=[0 0 0 0 0 0]
dmag=[ nan -3.27559662 -2.53676224 -2.3575325 -1.62550926 -2.81331825 nan nan]
r=24.7094020844
dmag_sig=[ nan -1.29201531 -1.58189809 -1.69529057 -2.23005438 -1.59269094 nan nan]

In [ ]: